﻿#ifndef CSqlOper_H
#define CSqlOper_H
/********************************************************************************
** @ Date:2025/04/17
** @ Author: HanJiaXin
** @ Description:数据库语句
** @ Version:1.0.0
** @ ClassName:
** @ Fun:
********************************************************************************/
#include "Header.h"
#include "dbstruct.h"
class CDevDataSensorSeries;
struct SSensorHisData;
struct SSensorSeriesAlarmInfo;
struct SChannel;

class CSqlOper
{
public:
	static CSqlOper& instance()
	{
		static CSqlOper instance;
		return instance;
	}

	bool initSql();
	
	//声振温设备相关
	bool selectDevInfo(QString& sDevGuid, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool insertDevInfo(QString& sDevGuid, QString& sDevName, QString& sSensorDevGuid, QString& sErrMsg);
	bool deleteDevInfo(QString sDevId, QString& sErrMsg);

	bool selectSensorSeriesInfo(QString sDevGuid, CDevDataSensorSeries* pDevData, QString sErrMsg);//根据设备Guid查询算法仓配置表
	bool selectSensorSeriesInfo(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString sErrMsg);//根据设备Guid查询算法仓配置表
	bool deleteSensorSeriesInfo(QString sDevGuid, QString sErrMsg);//根据设备Guid查询算法仓配置表
	bool insertDefDevCfg(QString sDevGuid,QString sDevName, QString sErrMsg);//添加默认的算法仓配置表
	bool selectSensorSeriesChannelInfo(QString sDevGuid, CDevDataSensorSeries* pDevData, QString sErrMsg);//根据设备Guid查询算法仓通道配置表
	bool selectSensorSeriesChannelInfo(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString sErrMsg);//根据设备Guid查询算法仓通道配置表
	bool deleteChannelInfo(QString sDevGuid, QString sErrMsg);//根据设备Guid查询算法仓通道配置表
	bool insertDefChannelCfg(QString sDevGuid, QString sErrMsg);//根据设备Guid插入默认的通道配置
	bool selectChannelByDevGuid(QString sDevGuid, QVector<QSqlRecord>& vecRecord, QString &sMsg);//根据设备Guid，查询所有通道
	bool updateSensorSeries(QString sDevGuid, QString sName, QString sIP, QString sUser, QString sPassWd, QString sBeltName, QString &sErrMsg);//更新声振温设备数据
	bool insertSensorSeries(QString sDevGuid, QString sName, QString sIP, QString sUser, QString sPassWd, QString sBeltName, QString &sErrMsg);//添加声振温设备数据
	bool updateChannelInfo(QString sDevGuid, QVector<SChannel> vecChannel, QString &sErrMsg);//更新通道信息
	bool insertChannelInfo(QString sDevGuid, QVector<SChannel> vecChannel, QString &sErrMsg);//添加通道信息
	bool insertSensorSeriesAlarm(SSensorSeriesAlarmInfo info, QString &sErrMsg);//插入声振温报警数据
	bool selectSensorSeriesAlarm(QString sDevDuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg);//查询声振温报警记录
	bool selectHisData(QString sDevGuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg);//根据时间段查询历史记录
	bool selectHisData(QVector<QString> vecDevGuid, QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecRecord, QString &sMsg);//根据时间段查询历史记录
	bool addSensorSeriesHistory(SSensorHisData& stData, QString sErrMsg);//插入历史记录

	bool selectTagID(QString& sDevGuid, QString& sTagID, QVector<QSqlRecord>& vecRecord, QString& sErrMsg);
	bool insertTagID(QString& sDevGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg);
	bool updateTagID(QString& sDevGuid, QString& sTagID, QString& sTagAddr, QString& sErrMsg);

	bool selectResultLastTime(QVector<QSqlRecord>& vecRecord, QString sErrMsg);
	bool insertResult(QString sGuid, int nResultType, QString sResultName, QDateTime dTime, QString sPath, QString sHttpUrl, QString& sErrMsg);
	bool selectResult(QString sStartTime, QString sEndTime, QVector<QSqlRecord>& vecInfo, QString& sErrMsg);
	bool selSeseResultInfo(QVector<QSqlRecord>& vecRecordSese,QString sStartTime,QString sEndTime,QString& sErrMsg);

private:
	CSqlOper();
	~CSqlOper();

	CSqlDllOper* m_pDbDllOper;
	QMutex* m_pMutex;
};

#endif // 